package com.yonyou.analytics;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.yonyou.ma.platform.modul.analytics.MaMobclickAgent;

import android.content.Intent;

public class Analytics extends CordovaPlugin {
	protected String appId = "wx0c5bd30aa791c589";
	protected String appKey = "";
	protected String appName = "";
	private String flag = "";
	private String pageName = "";

	@Override
	public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
		flag = args.getString(0);
		pageName = args.getString(1);

		if (flag.equals("login")) {
			Intent intent = cordova.getActivity().getIntent();
			JSONObject res = new JSONObject();
			res.put("account", intent.getStringExtra("loginName"));
			res.put("password", intent.getStringExtra("loginPass"));
			res.put("address", intent.getStringExtra("serverIp"));
			res.put("port", intent.getStringExtra("serverPort"));
			callbackContext.success(res);
		}
		// MaMobclickAgent.onResume(webView.getContext());

		if (flag.equals("clickApp")) {
			//MaMobclickAgent.onResume(webView.getContext());
		}
		if (flag.equals("goHome")) {
			//MaMobclickAgent.onPause(webView.getContext(), pageName);
		}

		return true;
	}

	// @Override
	// public void onResume(boolean multitasking) {
	// MaMobclickAgent.onResume(webView.getContext());
	// super.onResume(multitasking);
	// }
	//
	// @Override
	// public void onPause(boolean multitasking) {
	// MaMobclickAgent.onPause(webView.getContext(), pageName);
	// super.onPause(multitasking);
	// }

}
